package com.dks.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dks.mapper.PosterMapper;
import com.dks.models.Poster;
import com.dks.repository.IPosterRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class PosterRepository implements IPosterRepository {

    private PosterMapper posterMapper;

    @Autowired
    public PosterRepository(final PosterMapper posterMapperIn) {
        this.posterMapper = posterMapperIn;
    }

    @Override
    public Integer insert(Poster poster) {
        return posterMapper.insert(poster);
    }

    @Override
    public Integer update(Poster poster) {
        return posterMapper.update(poster);
    }

    @Override
    public Integer delete(Integer id) {
        return posterMapper.delete(id);
    }

    @Override
    public Poster select(Integer id) {
        return posterMapper.select(id);
    }

    @Override
    public Integer cntByMap(Map<String, Object> map) {
        return posterMapper.cntByMap(map);
    }

    @Override
    public List<Integer> getByMap(Map<String, Object> map) {
        return posterMapper.getByMap(map);
    }

    @Override
    public List<Poster> getByMapList(Map<String, Object> map) {
        return posterMapper.getByMapList(map);
    }

    @Override
    public Integer updateByCode(Poster poster) {
        return posterMapper.updateByCode(poster);
    }

    @Override
    public Poster selectByBfCode(String bfCode) {
        return posterMapper.selectByBfCode(bfCode);
    }

    @Override
    public ResultModel<Object> getPosterList(Integer pageNum, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("sortColumns", "app_sort ASC");
        map.put("recStatus", 0);
        Page p = PageHelper.startPage(pageNum, pageSize);
        List<Poster> posterList = posterMapper.getByMapList(map);
        PageInfo<Poster> pageInfo = new PageInfo<>(pageNum, pageSize, p.getTotal(), p.getPages(), posterList);
        return Result.makeResult(ResultInfo.SUCCESS, pageInfo);
    }
}
